package view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.JSplitPane;
import javax.swing.JTextPane;

import layout.TableLayout;

import com.hexidec.util.Translatrix;

import eventHandling.EventBus;
import eventHandling.EventTyp.Type;

/**
 * The CheckerDialog is used to ask the user to remember the reverse side of a
 * card.
 * 
 * @author sloth42
 * 
 */
public class CheckerDialog extends JDialog {

	private EventBus eventBus;
	private JPanel pnlCheckerButtons = new JPanel();
	private JSplitPane splitPane = new JSplitPane();
	private JTextPane tpFront = new JTextPane();
	private JTextPane tpReverse = new JTextPane();
	private JProgressBar pbUltraShortTime = new JProgressBar(
			JProgressBar.HORIZONTAL);
	private JProgressBar pbShortTime = new JProgressBar(JProgressBar.HORIZONTAL);

	private JButton btnSkip = new JButton(Translatrix
			.getTranslationString("skipCard"));
	private JButton btnFullscreen = new JButton(Translatrix
			.getTranslationString("fullscreen"));

	public CheckerDialog(EventBus eventBus, MainFrame mainFrame) {
		super();
		this.setModal(true);
		this.eventBus = eventBus;

		int border = 5;
		double[][] size = {
				{ border, 0.25, border, 0.25, border, 0.25, border, 0.25,
						border }, { border, TableLayout.FILL, 30, 30, border } };
		this.setLayout(new TableLayout(size));
		initSplitPane();
		initButtons();
		initProgressBars();
		setSize(500, 300);
	}

	private void initProgressBars() {
		this.add(pbUltraShortTime, "1,3,4,3");
		this.add(pbShortTime, "5,3,7,3");
	}

	private void initSplitPane() {
		splitPane.setLeftComponent(tpFront);
		splitPane.setRightComponent(tpReverse);
		this.add(splitPane, "1,1,7,1");
	}

	private void initButtons() {

		btnFullscreen.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent e) {
				eventBus.fireEvent(Type.FULLSCREEN_MODE_CHECKER_DIALOG);
			}
		});

		btnSkip.addActionListener(new ActionListener() {
		
			public void actionPerformed(ActionEvent e) {
				eventBus.fireEvent(Type.SKIP_CURRENT_CARD);
			}
		});

		this.add(btnSkip, "1,2");
		this.add(btnFullscreen, "3,2");
		this.add(pnlCheckerButtons, "5,2,7,2");

	}

	/**
	 * Returns the JPanel where a AnswerChecker can add its Buttons.
	 * 
	 * @return JPanel where AnswerChecker Buttons can be added.
	 */
	public JPanel getCheckerButtonsPanel() {
		return pnlCheckerButtons;
	}
	


}
